package demo8;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * Spring的配置类
 *
 * 被@Configuration注解的类，就是Spring的配置类
 */
@Configuration
@ComponentScan("demo8")//知名容器要扫描的那个包
public class Config {
    @Bean           //主动告诉容器将没有被@Conponent标注的类的这个对象放入容器中
    public Student getStudent(){
        return new Student();
    }
    @Bean
    public DruidDataSource initDruidDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true");
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        dataSource.setMaxActive(10);//池中的最大连接数
        dataSource.setInitialSize(5);//初始化链接数
        return dataSource;
    }

}
